home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWTrackr.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  11.6 KB  |  411 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWTrackr.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWTRACKR_H
  13. #include "FWTrackr.h"
  14. #endif
  15.  
  16. #ifndef FWVIEW_H
  17. #include "FWView.h"
  18. #endif
  19.  
  20. #ifndef FWFRAME_H
  21. #include "FWFrame.h"
  22. #endif
  23.  
  24. #ifndef FWDRGDRP_H
  25. #include "FWDrgDrp.h"
  26. #endif
  27.  
  28. #ifndef FWPART_H
  29. #include "FWPart.h"
  30. #endif
  31.  
  32. #ifndef FWCONTXT_H
  33. #include "FWContxt.h"
  34. #endif
  35.  
  36. #ifndef FWUTIL_H
  37. #include "FWUtil.h"
  38. #endif
  39.  
  40. #ifndef FWSCROLR_H
  41. #include "FWScrolr.h"
  42. #endif
  43.  
  44. #ifndef FWSESION_H
  45. #include "FWSesion.h"
  46. #endif
  47.  
  48. // ----- OS Includes -----
  49.  
  50. #ifndef FWRECT_H
  51. #include "FWRect.h"
  52. #endif
  53.  
  54. #ifndef FWEVENT_H
  55. #include "FWEvent.h"
  56. #endif
  57.  
  58. #ifndef FWEVENTU_H
  59. #include "FWEventU.h"
  60. #endif
  61.  
  62. #ifndef FWACQUIR_H
  63. #include "FWAcquir.h"
  64. #endif
  65.  
  66. // ----- Foundation Includes -----
  67.  
  68. #ifndef FWDEBUG_H
  69. #include "FWDebug.h"
  70. #endif
  71.  
  72. // ----- OpenDoc Includes -----
  73.  
  74. #ifndef SOM_ODTransform_xh
  75. #include <Trnsform.xh>
  76. #endif
  77.  
  78. #ifndef SOM_ODFacet_xh
  79. #include <Facet.xh>
  80. #endif
  81.  
  82. #ifndef SOM_ODFrame_xh
  83. #include <Frame.xh>
  84. #endif
  85.  
  86. #ifndef SOM_ODSession_xh
  87. #include <ODSessn.xh>
  88. #endif
  89.  
  90. #ifndef SOM_ODDragAndDrop_xh
  91. #include <DragDrp.xh>
  92. #endif
  93.  
  94. //========================================================================================
  95. //    Runtime Info
  96. //========================================================================================
  97.  
  98. #ifdef FW_BUILD_MAC
  99. #pragma segment framework
  100. #endif
  101.  
  102. //========================================================================================
  103. //    class FW_CBaseTracker
  104. //========================================================================================
  105.  
  106. //----------------------------------------------------------------------------------------
  107. //    FW_CBaseTracker::FW_CBaseTracker
  108. //----------------------------------------------------------------------------------------
  109.  
  110. FW_CBaseTracker::FW_CBaseTracker(Environment *ev, FW_CView* view, ODFacet* facet) :
  111.     fFacet(facet),
  112.     fView(view)
  113. {
  114. FW_UNUSED(ev);
  115.     FW_ASSERT(view);
  116.     FW_ASSERT(facet);
  117. }
  118.  
  119. //----------------------------------------------------------------------------------------
  120. //    FW_CBaseTracker::~FW_CBaseTracker
  121. //----------------------------------------------------------------------------------------
  122.  
  123. FW_CBaseTracker::~FW_CBaseTracker()
  124. {
  125. }
  126.  
  127. //========================================================================================
  128. //    class FW_CDropTracker
  129. //========================================================================================
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    FW_CDropTracker::FW_CDropTracker
  133. //----------------------------------------------------------------------------------------
  134.  
  135. FW_CDropTracker::FW_CDropTracker(Environment *ev, FW_CView* view, ODFacet* facet, FW_Boolean autoScroll) :
  136.     FW_CBaseTracker(ev, view, facet),
  137.     fScroller(view->GetFrame(ev)->GetScroller(ev)),
  138.     fAutoScroll(autoScroll)
  139. #ifdef FW_BUILD_MAC
  140.     ,fMacHiliteOn(FALSE),
  141.     fSavedHiliteState(FALSE)
  142. #endif
  143. #ifdef FW_DEBUG
  144.     ,fHandleBeginTrackingCalled(FALSE)
  145. #endif
  146. {
  147.     fAutoScroll = fAutoScroll && fScroller;
  148. }
  149.  
  150. //----------------------------------------------------------------------------------------
  151. //    FW_CDropTracker::~FW_CDropTracker
  152. //----------------------------------------------------------------------------------------
  153.  
  154. FW_CDropTracker::~FW_CDropTracker()
  155. {
  156. }
  157.  
  158. //----------------------------------------------------------------------------------------
  159. //    FW_CDropTracker::HandleBeginTracking
  160. //----------------------------------------------------------------------------------------
  161. //    where is in frame coordinate
  162.  
  163. void FW_CDropTracker::HandleBeginTracking(Environment *ev, const FW_CPoint& where, unsigned long dragAttributes)
  164. {    
  165. #ifdef FW_DEBUG
  166.     fHandleBeginTrackingCalled = TRUE;
  167. #endif
  168.  
  169.     fDragAttributes = dragAttributes;
  170.     
  171.     FW_CPoint anchorPoint(where);
  172.     FW_FrameToContent(ev, GetFacet(ev)->GetFrame(ev), anchorPoint);
  173.     fAnchorPoint = this->BeginTracking(ev, anchorPoint);
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    FW_CDropTracker::HandleContinueTracking
  178. //----------------------------------------------------------------------------------------
  179. //    where is in frame coordinate
  180.  
  181. void FW_CDropTracker::HandleContinueTracking(Environment *ev, const FW_CPoint& where)
  182. {
  183.     FW_CPoint currentPoint(where);
  184.     FW_FrameToContent(ev, GetFacet(ev)->GetFrame(ev), currentPoint);
  185.     fPreviousPoint = this->ContinueTracking(ev, fAnchorPoint, fPreviousPoint, currentPoint);
  186. }
  187.  
  188. //----------------------------------------------------------------------------------------
  189. //    FW_CDropTracker::HandleEndTracking
  190. //----------------------------------------------------------------------------------------
  191. //    where is in frame coordinate
  192.  
  193. FW_Boolean FW_CDropTracker::HandleEndTracking(Environment *ev, const FW_CPoint& where)
  194. {
  195.     FW_CPoint currentPoint(where);
  196.     FW_FrameToContent(ev, GetFacet(ev)->GetFrame(ev), currentPoint);
  197.     return this->EndTracking(ev, fAnchorPoint, currentPoint);
  198. }
  199.  
  200. //----------------------------------------------------------------------------------------
  201. //    FW_CDropTracker::BeginTracking
  202. //----------------------------------------------------------------------------------------
  203.  
  204. FW_CPoint FW_CDropTracker::BeginTracking(Environment* ev, const FW_CPoint& anchorPoint)
  205. {
  206.     if (!IsInSourceFrame(ev))
  207.         PrivShowDefaultHilite(ev);
  208.     
  209.     if (fAutoScroll)
  210.         fScroller->InitializeAutoScroll(ev);
  211.  
  212.     return anchorPoint;
  213. }
  214.  
  215. //----------------------------------------------------------------------------------------
  216. //    FW_CDropTracker::BeginTracking
  217. //----------------------------------------------------------------------------------------
  218.  
  219. FW_CPoint FW_CDropTracker::ContinueTracking(Environment* ev,
  220.                                             const FW_CPoint& anchorPoint, 
  221.                                             const FW_CPoint& previousPoint, 
  222.                                             const FW_CPoint& currentPoint)
  223. {
  224. FW_UNUSED(anchorPoint);
  225. FW_UNUSED(previousPoint);
  226.     if (fAutoScroll)
  227.     {
  228.         FW_CPoint autoScrollOffset = fScroller->AutoScrollOffset(ev, currentPoint, 30);
  229.         if (autoScrollOffset != FW_kZeroPoint)
  230.         {
  231.             if (fMacHiliteOn)
  232.             {
  233.                 fSavedHiliteState = fMacHiliteOn;
  234.                 this->HideDragHilite(ev);
  235.             }    
  236.             fScroller->ScrollBy(ev, autoScrollOffset);    
  237.         }
  238.         else
  239.         {
  240.             if (fSavedHiliteState)
  241.                 PrivShowDefaultHilite(ev);
  242.         }
  243.     }
  244.  
  245.     return currentPoint;
  246. }
  247.  
  248. //----------------------------------------------------------------------------------------
  249. //    FW_CDropTracker::EndTracking
  250. //----------------------------------------------------------------------------------------
  251.  
  252. FW_Boolean FW_CDropTracker::EndTracking(Environment* ev,
  253.                                         const FW_CPoint& anchorPoint, 
  254.                                         const FW_CPoint& lastPoint)
  255. {
  256.     this->HideDragHilite(ev);    
  257.     return anchorPoint != lastPoint;
  258. }
  259.  
  260. //----------------------------------------------------------------------------------------
  261. //    FW_CDropTracker::ShowDragHilite
  262. //----------------------------------------------------------------------------------------
  263. // hiliteShape is in frame coordinate
  264.  
  265. void FW_CDropTracker::ShowDragHilite(Environment* ev, ODShape* hiliteShape, FW_Boolean showInside)
  266. {    
  267. #ifdef FW_BUILD_MAC
  268.     FW_ASSERT(fMacHiliteOn == FALSE);
  269.     FW_ASSERT(hiliteShape);
  270.     
  271.     ODFacet* facet = GetFacet(ev);
  272.     FW_CFrame* frame = GetView(ev)->GetFrame(ev);
  273.     FW_ASSERT(facet->GetFrame(ev) == frame->GetODFrame(ev));    //just to be sure
  274.  
  275.     FW_CWindowContext gc(ev, facet);        // focus drawing to the window
  276.  
  277.     FW_CAcquiredODShape aqHiliteShape = hiliteShape->Copy(ev);
  278.  
  279.     // ----- Intersect it with the aggregateClipShape -----
  280.     FW_CAcquiredODShape aqClipShape = GetFacet(ev)->AcquireAggregateClipShape(ev, NULL);
  281.     aqHiliteShape->Intersect(ev, aqClipShape);
  282.  
  283.     FW_FrameToWindow(ev, GetFacet(ev), aqHiliteShape);
  284.     
  285.     ::ShowDragHilite(FW_CSession::GetDragAndDrop(ev)->GetDragReference(ev), 
  286.                      aqHiliteShape->GetQDRegion(ev), 
  287.                      showInside);
  288.     
  289.     fMacHiliteOn = TRUE;
  290.     fSavedHiliteState = FALSE;
  291. #endif
  292. }
  293.  
  294. //----------------------------------------------------------------------------------------
  295. //    FW_CDropTracker::HideDragHilite
  296. //----------------------------------------------------------------------------------------
  297.  
  298. void FW_CDropTracker::HideDragHilite(Environment* ev)
  299. {
  300. #ifdef FW_BUILD_MAC
  301.     if (fMacHiliteOn)
  302.     {
  303.         FW_CWindowContext gc(ev, GetFacet(ev));        // focus drawing to the window
  304.         ::HideDragHilite(FW_CSession::GetDragAndDrop(ev)->GetDragReference(ev));
  305.         
  306.         fMacHiliteOn = FALSE;
  307.     }
  308. #endif
  309. }
  310.  
  311. //----------------------------------------------------------------------------------------
  312. //    FW_CDropTracker::PrivShowDefaultHilite
  313. //----------------------------------------------------------------------------------------
  314.  
  315. void FW_CDropTracker::PrivShowDefaultHilite(Environment* ev)
  316. {
  317.     FW_CAcquiredODShape aqHiliteShape = GetView(ev)->GetFrame(ev)->GetDroppable(ev)->AcquireDragHiliteShape(ev, GetFacet(ev));
  318.     this->ShowDragHilite(ev, aqHiliteShape, TRUE);
  319. }
  320.  
  321. //----------------------------------------------------------------------------------------
  322. //    FW_CDropTracker::IsInSourceFrame
  323. //----------------------------------------------------------------------------------------
  324.  
  325. FW_Boolean FW_CDropTracker::IsInSourceFrame(Environment* ev) const
  326. {
  327. FW_UNUSED(ev);
  328.  
  329. #ifdef FW_DEBUG
  330.     FW_ASSERT(fHandleBeginTrackingCalled);
  331. #endif
  332.  
  333.     return (fDragAttributes & kODDragIsInSourceFrame);
  334. }
  335.  
  336. //----------------------------------------------------------------------------------------
  337. //    FW_CDropTracker::GetDragAttributes
  338. //----------------------------------------------------------------------------------------
  339.  
  340. unsigned long FW_CDropTracker::GetDragAttributes(Environment* ev) const
  341. {
  342. FW_UNUSED(ev);
  343.  
  344. #ifdef FW_DEBUG
  345.     FW_ASSERT(fHandleBeginTrackingCalled);
  346. #endif
  347.     return fDragAttributes;
  348. }
  349.  
  350.  
  351. //========================================================================================
  352. //    class FW_CTracker
  353. //========================================================================================
  354.  
  355. //----------------------------------------------------------------------------------------
  356. //    FW_CTracker::FW_CTracker
  357. //----------------------------------------------------------------------------------------
  358.  
  359. FW_CTracker::FW_CTracker(Environment *ev, FW_CView* view, ODFacet* facet, FW_Boolean waitMouseMoved) :
  360.     FW_CBaseTracker(ev, view, facet),
  361.     fWaitMouseMoved(waitMouseMoved)
  362. {
  363. }
  364.  
  365. //----------------------------------------------------------------------------------------
  366. //    FW_CTracker::~FW_CTracker
  367. //----------------------------------------------------------------------------------------
  368.  
  369. FW_CTracker::~FW_CTracker()
  370. {
  371. }
  372.  
  373. //----------------------------------------------------------------------------------------
  374. //     FW_CTracker::Track
  375. //----------------------------------------------------------------------------------------
  376.  
  377. FW_Boolean FW_CTracker::Track(Environment *ev, const FW_CMouseEvent& theMouseEvent)
  378. {
  379.     FW_ASSERT(GetFacet(ev) != NULL);
  380.     FW_ASSERT(GetView(ev) != NULL);
  381.  
  382.     // ----- Flush update event pending for this window
  383.     FW_CAcquiredODWindow aqWindow = GetFacet(ev)->GetFrame(ev)->AcquireWindow(ev);
  384.     aqWindow->Update(ev);
  385.     
  386.     if (fWaitMouseMoved && !theMouseEvent.WaitUntilMouseMoved(ev))
  387.         return FALSE;
  388.     
  389.     FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  390.     GetView(ev)->FrameToViewContent(ev, where);
  391.  
  392.     fAnchorPoint = BeginTracking(ev, where);
  393.     
  394.     FW_CPoint currentLoc;
  395.     fPreviousPoint = fAnchorPoint;
  396.     
  397.     do  
  398.     {    
  399.         {
  400.             FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  401.             currentLoc = ::FW_GetMouseLocation(aqWindow, vc);
  402.         }
  403.         
  404.         fPreviousPoint = ContinueTracking(ev, fAnchorPoint, fPreviousPoint, currentLoc);
  405.     } 
  406.     while (FW_WaitMouseUp());
  407.     
  408.     return EndTracking(ev, fAnchorPoint, currentLoc);
  409. }
  410.  
  411.